import 'package:flutter/material.dart';
import 'package:secend_flutter/bean/home_common_model_bean.dart';
import 'package:secend_flutter/bean/home_sales_box_model_bean.dart';
import 'package:secend_flutter/dao/tao_ean.dart';
import 'package:secend_flutter/define_widget/webview_widget.dart';

import '../main.dart';

class SalesBox extends StatelessWidget {
  final SalesBoxBean? salesBoxBean;
  const SalesBox({Key? key, this.salesBoxBean}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: const BoxDecoration(color: Colors.white),
      child: Column(
        children: _items(context)
      ),
    );
  }

  _items(BuildContext context){
      List<Widget> items=[];
      if(salesBoxBean==null)return items;
      items.add(_title( context),);
      items.add(_doubleItem(context,salesBoxBean!.bigCard1,salesBoxBean!.bigCard2,
          true,false));
      items.add(_doubleItem(context,salesBoxBean!.smallCard1,salesBoxBean!.smallCard2,
          false,false));
      items.add(_doubleItem(context,salesBoxBean!.smallCard3,salesBoxBean!.smallCard4,
          false,true));
      return items;

  }
  Widget _doubleItem(BuildContext context, CommonBean card1, CommonBean card2,
      bool big, bool last) {
      return Row(
        children: [
          _item(context,card1,big,true,last),
          _item(context,card2,big,false,last),
        ],
      );
  }
  _item(BuildContext context, CommonBean card, bool big,bool left, bool last) {
    BorderSide side=const BorderSide(width: 0.8,color: Color(0xfff2f2f2));
    return GestureDetector(
      onTap: () {
        Tiaboon.push(
            navigatorKey.currentState!.overlay!.context,
            MyWebView(
              url: card.url,
              statusBarColor: card.statusBarColor,
              hideAppBar: card.hideAppBar,
            ));
      },
      child:Container(
        decoration: BoxDecoration(
          border: Border(
            right: left?side:BorderSide.none,
            bottom: last?BorderSide.none:side
          )
        ),
        child: Image.network(
          card.icon!,
          fit: BoxFit.fill,
          width: MediaQuery.of(context).size.width/2-10,//屏幕宽度
          height: big?129:80,
        ),
      ),
    );

  }


  _title(BuildContext context){
    return Container(
      height: 44,
      margin: const EdgeInsets.only(left: 10),
      padding: const EdgeInsets.only(top: 7),
      decoration: const BoxDecoration(border: Border(bottom: BorderSide(width: 1.0,color: Colors.black12))),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Image.network(salesBoxBean!.icon,height: 18,),
          Container(
            decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(12),
              gradient: const LinearGradient(
                colors: [
                  Color(0xffff4e63),
                  Color(0xffff6cc9),
                ],
                end: Alignment.centerRight,
                begin: Alignment.centerLeft,
              )
            ),
            child: GestureDetector(
              onTap: () {
                Tiaboon.push(
                  context,
                  MyWebView(url: salesBoxBean!.moreUrl, title: '更多活动'),
                );
              },
              child: const Text(
                '获取更多福利 >',style: TextStyle(color: Colors.white,fontSize:13 ),
              ),
            ),
          )
        ],
      ),
    );
  }




}
